<?php if ($manga_selected == 0) :?>
<h3 class="noMargin blur" id="mangaSelected">
	Manga Selected: You not choose manga
</h3>
<?php else: ?>
<h3 class="noMargin selected" id="mangaSelected">
	Manga Selected:
	<?php if ($this->manga_model->loadByPK($manga_selected)->isLoaded()) :?>
		<a href="<?php echo $this->manga_model->getMangaUrl() ?>"><?php echo $this->manga_model->getName(); ?></a>
	<?php endif; ?>
	<?php if ($this->manga_chapter_model->getMangaId() != 0) :?>
		<input type="button" id="btnResetMangaSelected" value="Reset Manga Selected" />
	<?php endif; ?>
</h3>
<?php endif; ?>
<?php echo form_open_multipart('admin/catalog/chapter/manga', array('id' => 'frmMangaGridView')); ?>
<?php echo fx_control::newInstance('formKey')->createType('hidden')->setData('value', random_string('unique', 16))->render(); ?>
<?php echo fx_control::newInstance('manga_selected')->createType('hidden')->setData('value', $manga_selected)->render(); ?>
<div class="gridContainer autoCenter noMargin">
	<!-- GRID HEADER -->
	<div class="gridHeader block">
		<table class="fullWidth">
			<tr>
				<td class="column50">
					<h3 class="moduleHeader">
						Manga Browser
					</h3>
				</td>
				<td class="column50 rightAlign">
					<button type="button" onclick="window.location='<?php echo site_url("admin/catalog/manga/edit", true)?>'">
						<span>Add New Manga</span>
					</button>
				</td>
			</tr>
		</table>
	</div>
	<!--TOOL-->
	<div class="gridTools"> 
		<table class="fullWidth">
		<tr>
			<td>
				Page
				<?php if ($paginator->getCurrentPageNumber() <= 1) :?>
					<img src="<?php echo base_url() . 'skins/default/images/admin/gridview/pager_arrow_left_off.gif' ?>" align="bottom" border="0"/>
				<?php else: ?>
					<a href="#">
						<img src="<?php echo base_url() . 'skins/default/images/admin/gridview/pager_arrow_left.gif' ?>" align="bottom" border="0" onclick="prevPage('mangaPageIndex', 'frmMangaGridView')"/>
					</a>
				<?php endif; ?>
					<input type="text" class="inputText pageIndex" id="mangaPageIndex" value="<?php echo $paginator->getCurrentPageNumber() ?>" name="page" style="width:20px"/>
				<?php if ($paginator->getCurrentPageNumber() >= $paginator->count()) :?>
					<img src="<?php echo base_url() . 'skins/default/images/admin/gridview/pager_arrow_right_off.gif' ?>" align="bottom" border="0"/>
				<?php else: ?>
					<a href="#">
						<img src="<?php echo base_url() . 'skins/default/images/admin/gridview/pager_arrow_right.gif' ?>" align="bottom" border="0" onclick="nextPage('mangaPageIndex', 'frmMangaGridView', <?php echo $paginator->count() ?>)"/>
					</a>
				<?php endif; ?>
				of <?php echo $paginator->count() ?> pages
				<span class="separator">|</span>
				View
				<?php echo fx_control::newInstance('recordPerPage')
							 ->createType('option')
							 ->addOption('20', 20)
							 ->addOption('30', 30)
							 ->addOption('50', 50)
							 ->addOption('100', 100)
							 ->addOption('200', 200)
							 ->addClass('selectRecordPerPage')
							 ->bindingOption($paginator, 'getItemCountPerPage')
							 ->render(); 
				?>
				on page
				<span class="separator">|</span>
				Total <?php echo $this->manga_model->countAll(); ?> manga, found
				<span class="no-display" id="total-count"><?php echo $found; ?></span> manga
			</td>
			<td align="right">
				&nbsp;
			</td>
			<td align="right">
				<div align="right" class="buttonSet">
					<button type="submit">
						<span>Search</span>
					</button>
					<button type="reset" id="btnResetGridForm" onclick="resetAjaxForm('frmMangaGridView', 'mangaGridviewContainer')">
						<span>Reset Filter</span>
					</button>
				</div>
			</td>
		</tr>
		</table>
	</div>		
        <!--PRODUCT COLLECTION-->
	<table class="gridview" id="mangaGridview">
		<thead>
		<!--COLUMN HEADER-->
		<tr class="columns">
			<input type="hidden" name="mangaOrder[name]" value="<?php echo $sorter->getName() ?>" id="mangaOrder"/>
			<input type="hidden" name="mangaOrder[direction]" value="<?php echo $sorter->getDirection() ?>" id="mangaOrderDirection"/>
			<th><span></span></th>
			<th id="manga_id" class="columnFilter"><span>ID</span></th>
			<th id="manga_id" class="columnFilter"><span>Index</span></th>
			<th id="manga_name" class="columnFilter"><span>Name</span></th>
		</tr>
		<!--COLUMN FILTER-->
		<tr class="filters">
			<th style="width: 30px"></th>
			<th style="width: 120px">
				<div class="clear">
					<span class="filterLabel left">From</span>
					<input class="filterField left" type="text" name="mangaFilter[id][value][from]" value="<?php echo $filters->getValueFrom('id'); ?>"/>
					<input type="hidden" name="mangaFilter[id][type]" value="range"/>
				</div>
				<div class="clear">
					<span class="filterLabel left">To</span>
					<input class="filterField left" type="text" name="mangaFilter[id][value][to]" value="<?php echo $filters->getValueTo('id'); ?>"/>
				</div>
			</th>
			<th style="width: 120px">
				<div class="clear">
					<span class="filterLabel left">From</span>
					<input class="filterField left" type="text" name="mangaFilter[volume_index][value][from]" value="<?php echo $filters->getValueFrom('volume_index'); ?>"/>
					<input type="hidden" name="mangaFilter[volume_index][type]" value="range"/>
				</div>
				<div class="clear">
					<span class="filterLabel left">To</span>
					<input class="filterField left" type="text" name="mangaFilter[volume_index][value][to]" value="<?php echo $filters->getValueTo('volume_index'); ?>"/>
				</div>
			</th>
			<th>
				<div class="clear">
					<input type="text" name="mangaFilter[name][value]" value="<?php echo $filters->getValue('name'); ?>" style="width: 89%"/>
					<input type="hidden" name="mangaFilter[name][type]" value="string"/>
				</div>						
			</th>
			<th></th>
		</tr>
		</thead>
		<tbody>
			
			<?php foreach ($collection as $manga) :?>
			<tr id="row_<?php echo $manga->getId()?>" class="activeRow<?php if ($this->manga_chapter_model->getMangaId() == $manga->getId()) echo ' mangaSelected' ?>">
				<input class="editUrl" type="hidden" value="<?php echo $manga->getMangaUrl(); ?>" />
				<td class="noActiveRow">
					<?php echo fx_control::newInstance('radManga')
										 ->createType('radio')
										 ->removeClass('inputText')
										 ->addClass('radManga')
										 ->value($manga->getId())
										 ->bindingValue($manga_selected)
										 ->render();
					?>
				</td>
				<td><?php echo $manga->getId() ?></td>
				<td><?php echo $manga->getVolumeIndex() ?></td>
				<td><?php echo $manga->getName() ?></td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>
</div>
<?php echo form_close(); ?>
<script language="javascript" type="text/javascript">
	function showMangaSelected(data) 
	{
		jQuery("#mangaSelected").html(data);
	}
	
	jQuery("#mangaGridview")
	.decorateTable()
	.lightHoverRow()
	.activeSortableAbility("frmMangaGridView", "columnFilter", "manga_", "mangaOrder", "mangaOrderDirection")
	.activeAjaxForm('frmMangaGridView', 'mangaGridviewContainer')
	.radioCallbackHandler('radManga', 'manga_selected', '<?php echo site_url('admin/catalog/chapter/selectManga/', true)?>', showMangaSelected)
	.activeEditRow();

	jQuery("#btnResetMangaSelected").click(function(){
		var store = jQuery("#manga_selected");
		if (!jQuery(store).exists()) {
			return;
		}
		jQuery(store).attr("value", 0);
		jQuery(".radManga").attr("checked", "");
		var url = '<?php echo site_url('admin/catalog/chapter/resetmanga', true)?>';
		jQuery.ajax({
			type: 'POST',
			url: url,
			success: function(data) {
				jQuery("#mangaSelected").removeClass("selected").addClass("blur").html(data);
			}
		});
	});
</script>
